package com.ruoyi.web.controller.project;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.system.domain.ProjectManagement;
import com.ruoyi.system.domain.SysLogininfor;
import com.ruoyi.system.service.IProjectManagementService;
import com.ruoyi.system.service.ISysLogininforService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author ZHAONZ
 * @version 1.0
 * @date 2023/6/11 14:28
 */
@Controller
@RequestMapping("/project/management")
public class ManagementIndexControrller extends BaseController {

    private String prefix = "project/overview";

    @Autowired
    private ISysLogininforService logininforService;

    @Autowired
    private IProjectManagementService projectManagementService;

    @GetMapping("/index")
    public String index(ModelMap mmap)
    {
        mmap.put("version", RuoYiConfig.getVersion());

        PageHelper.startPage(1, 5, "login_time desc");
        List<SysLogininfor> list = logininforService.selectLogininforList(new SysLogininfor());
        mmap.put("logininfor", list);

        PageHelper.startPage(1, 5, "update_time desc");
        List<ProjectManagement> managementList = projectManagementService.list();

        mmap.put("managementList", managementList);

        long count = projectManagementService.count();
        mmap.put("count", count);

        long endCount = projectManagementService.count(new QueryWrapper<ProjectManagement>().eq("project_schedule", "END"));
        mmap.put("endCount", endCount);

        long completeCount = projectManagementService.selectManagementComplete();
        mmap.put("completeCount", completeCount);

        long neCount = projectManagementService.count(new QueryWrapper<ProjectManagement>()
                .ne("project_schedule", "END").eq("create_by", super.getSysUser().getLoginName()));
        mmap.put("neCount", neCount);

        return prefix + "/index";
    }
}
